/**
 * 网页保存为PDF
 */
const puppeteer = require("puppeteer");
let browser;
let page;

const urls = [
  "https://mp.weixin.qq.com/s?__biz=MzkwODIwMDY2OQ==&mid=2247488275&idx=1&sn=50c950795f45b6902be4ddcedffda21b&source=41#wechat_redirect",
  "",
  "https://mp.weixin.qq.com/s/lYHCNSEiJrWo1ayM0CPcJg",
  "",
  "https://github.com/whinc/whinc.github.io/issues/22",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247486192&idx=1&sn=6d2e77cf782a81e44c79621fd772074f&chksm=cedff796e9ec559e5e5e8f7d14a9b5ec426a59f48927f51ee921e3e52d4521a3f43991d04816&scene=126&sessionid=1705541360#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247486214&idx=1&sn=4414ce334a7630d9824c7a9053e2e8e0&chksm=ce245d68e363da9decc8f74c2602f42df5fcbe9138b82ed8d7241a25f7531ed31073086d5b01&scene=126&sessionid=1705541360#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247486223&idx=1&sn=d7979b4e486c52ec92238cb0ad807c1e&chksm=ce49462fc1cf73057571ff9d5a8cdbf53ed098de59d2ce89e1fdf969d9f2eb9f3a4d452c28ee&scene=126&sessionid=1705541360#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247486239&idx=1&sn=6d0738be1ffc1219da87d85004791428&chksm=ce17602387a6959f6be02fabd022092e1be14006cd8d2052061520b8bd91b9224e4d19109e0d&scene=126&sessionid=1705541360#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247486066&idx=1&sn=5a0242d7e8c29605850dee647f2aa98a&chksm=ceb36d93053a2e7a6e8694345dab7cb29601f33b41f8c0047cc92b34c2e4aebea719ff1cc033&scene=126&sessionid=1705541360#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485916&idx=1&sn=7544f0fec8b9ae0f0c7034468792374d&chksm=ce502f8bfd3e95a1dad2839d8268d20a00ac2e9cad5faa2117824fc9469da334cb60decf2eaa&scene=126&sessionid=1705541400#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485840&idx=1&sn=87b0cb6e978910afebb46abd50ce91f6&chksm=ce5a05b90b639267845045fc50f36c4c5c41c80b4ad144cbf73cd9a2dfdfea1a122fd319b138&scene=126&sessionid=1705541400#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485784&idx=1&sn=f9e1ed47e58a3e67ae114e3e21f77ed8&chksm=cea4af4394ea4a9e2a7e414a50b4fdc7ae3e8706d1e4830112cb8dead6d558fe28633d4f10cf&scene=126&sessionid=1705541400#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485772&idx=1&sn=79e27bcbe24f6fe14c184dfe016e1419&chksm=cee94deeaa1bf33682d755db5ed00e658c892eff40cc249f244cf01104d4c5f276d735783d20&scene=126&sessionid=1705541400#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485713&idx=1&sn=f291190758a98d7274b7e3ddca34cbd3&chksm=ce79a61530fc29d6d280b4c3644b36705f0b56e2c352669334b26eeff08657f3e8848c4040e5&scene=126&sessionid=1705541435#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485677&idx=1&sn=19c32e530cb3ae13879f6e7f8a8329ae&chksm=ce93ebad63adf37cdd67ae1d2dcbea2206a3e16d456a8eb6f5924e0b5899d8a302984d542088&scene=126&sessionid=1705541435#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485625&idx=1&sn=80921b9cfc34324ec579a7d8a69db0b5&chksm=cef21c1b08f5480c1552530c43577467c9f6dbc92a088257cbb8bf8520a2215dd22e50fa70bb&scene=126&sessionid=1705541435#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485605&idx=1&sn=319b2e90be667df592926ae208c22ee5&chksm=ce531362fbcc09d9e1802075306c3e6385e5b1a963438c9329d0bd382a09f1a802cdb2085c98&scene=126&sessionid=1705541435#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485559&idx=1&sn=e77a56c73ad2a93b8b32701cd7d13db4&chksm=cee039ab6bb75cc4b611905bd0f4aeb1a95b946f5ac00ed4b3b7cbc0ee365182c357d9be9b43&scene=126&sessionid=1705541463#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485535&idx=1&sn=3685de1959484b8535bb51ce98789714&chksm=ce395139ff112f3e01bdd428d26029ecc4d14a578f1b878b2f52eb382be89d55d46564bec89a&scene=126&sessionid=1705541463#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485431&idx=1&sn=6b5333a1efaf85e3c8edebcebbab8415&chksm=ce6b3a81fa1da3ecae86b01bedfd946f2a8ab3ae1bc550a2793f59f53e61d2544621680b9b00&scene=126&sessionid=1705541463#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485325&idx=1&sn=9bef25975bf2c65969310b448059c04e&chksm=ce4366965f3d6dcdc4b12eb81c34e14a1edd5327d6d3bd75bcf341bd4fe0b8e072b8fb770086&scene=126&sessionid=1705541463#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485264&idx=1&sn=53e4cca11a2f1c70be1203c1d1d41ddd&chksm=ce59e81f2fc5a25fa1d2ab58cf0e3dd41879feedefc00a9306208c234b5d17b313761762ca35&scene=126&sessionid=1705541491#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485180&idx=1&sn=a1d253bac28910514c7355c081114923&chksm=ce8bd9cbfc14d34d214cf48073404f6a2bb2c8abc959680f23a9e3134a46a92fd240f42a0162&scene=126&sessionid=1705541491#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247485067&idx=1&sn=3ec42bc3adea913df3190ba46f8a782b&chksm=ceacce51bd3443be765ed3f108663240d021ea358aab0ae0e96057ea659967178fc27a4f9b9e&scene=126&sessionid=1705541491#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484927&idx=1&sn=1db887b65e6d6c4279e412ea9c72a581&chksm=ce949d2616c04f4abd9de3b5f2f82538183902cddc223bd5d90cf9e7131f77f37b2febc5ef49&scene=126&sessionid=1705541516#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484662&idx=1&sn=e968e9719f5667f4423e0694d5f5b9ee&chksm=ce4bf98c045488fcd5deb46043fa570f2426e7770d2ae1e68bb18644f5305053fe8f05940bfa&scene=126&sessionid=1705541516#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484540&idx=1&sn=db06f85de9a7a0801b5c885fe71bc59c&chksm=cefc0e6863c7b9cce2c40f44f5a7af4668eba5308a2f0bc6e68e58643658a1df1b307a3acab0&scene=126&sessionid=1705541544#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484527&idx=1&sn=6dedefc865a29bee2a853f78ba8f4b72&chksm=cea36c531d8010100d894b25f7b90a593fe9745a1f68f7f526a59ec8a884e1755b9d3aa50da4&scene=126&sessionid=1705541544#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484484&idx=1&sn=dfc14209eab9243c91f1f0600bb2fcbc&chksm=ce82433c8069f0ecc3533ad43fd4d269d6d05e47f882130b3c4044edaa6c274214f5bd3733e8&scene=126&sessionid=1705541544#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484474&idx=1&sn=ebddde6063379bdc8758adbfdde949ce&chksm=ce18de47a1cccf721babff0ee3cefd189e3a97dea057412da5689523cb2a153c5b48f0c3ac62&scene=126&sessionid=1705541544#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484407&idx=1&sn=83832b68247e709e39d0bc7d850928fd&chksm=ce0ccdb2a930e0444a4dc8d03ee0bb9aca2493f28a44717aee08340247e91c0bf8a4a608785f&scene=126&sessionid=1705541544#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484384&idx=1&sn=b7147a56b8f01fe794ed229d09e37b74&chksm=ced32a427559a62a327b8f1a17bad23f7579c81b6d224d9d0ff78840bd64942c1e9fe9768f0c&scene=126&sessionid=1705541544#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484316&idx=1&sn=411e88180636272c6ba7a4e2b9bd675d&chksm=ce174be3d2966c2302fa055c90143605bcb03108f368e500e3178ec55f26a936288ca85b6a4f&scene=126&sessionid=1705541544#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484261&idx=1&sn=1869ebe9be0d2cdc9d48bb202a3ec8f4&chksm=cea20a7a049abafce24f0991a0a125da5f2ea649f6ba6511f5f740ed9083c0e483f0af9af724&scene=126&sessionid=1705541573#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484251&idx=1&sn=17955b33a50b67504d0b9c9057d7d69a&chksm=ce3548eb535c62a10770b5c47a5986b9800844924b69da5d0ac4a93c49b005cbf35b9f38c1d2&scene=126&sessionid=1705541573#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484235&idx=1&sn=1e4a43ded25ce266a6594fc4197ef415&chksm=ce33f41268495b8e124908acbfb84d04974624b0e3c6d2aa54544965784c9d604a76c3e39b8b&scene=126&sessionid=1705541573#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484224&idx=1&sn=c4d5163671894ac697ed7eab1471d2c8&chksm=ce191c2b959ecd5150ed3319ce56ecb9284dd0b4ecb6b6b9303d5f00a11546a2620739137587&scene=126&sessionid=1705541573#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484212&idx=1&sn=b8bc6323b96e5ff9248d5af2bc75114a&chksm=cead41fe1211437a9512eef8c37b4f02a6f71401af51141c0626a3bd437170ae296419124dc5&scene=126&sessionid=1705541573#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484195&idx=1&sn=b6180033106e3364d699e641c645cb56&chksm=ceb13605d0c59f2b11705fc2326a932989f4253589f90d8826735ceb6569ee6b27042f974e49&scene=126&sessionid=1705541573#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484076&idx=1&sn=8d321fc32775ba7e1c854eaafd850853&chksm=ce1e0fd8dc6fdc530000043188a0426bdbd6ef6470965014233b181a920eb0a7541c538403b8&scene=126&sessionid=1705541596#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247484030&idx=1&sn=8762ed574de2696d840bd98c6aebae17&chksm=cee524981aa67ced4a52131aab83c50ad67fb2c568cedf229fc1fee375ec8a553eb247793615&scene=126&sessionid=1705541596#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247483952&idx=1&sn=a884a60e966b2913a4b29c0133916d73&chksm=ceaea10c92c9f4c5f6b457ff6a45ef462e8a2226f8dd1d62aac4202fcd7a431710b1379d7016&scene=126&sessionid=1705541596#rd",
  "",
  "https://mp.weixin.qq.com/s?__biz=Mzg4NTk4MjI3NA==&mid=2247483769&idx=1&sn=20ce486de65f53c6977b07c0f7430b11&chksm=ce2cb1a8667edcac22ca741d686ab0370fdf010389b1b55eb1ac40d6cbcc6fc4659f3e67f85b&scene=126&sessionid=1705541624#rd",
  "",
  "https://mp.weixin.qq.com/s/lYHCNSEiJrWo1ayM0CPcJg",
  "",
  "https://mp.weixin.qq.com/s/aQclSEHFER-Tsr2LaYtm-A",
];

const main = async () => {
  browser = await puppeteer.launch({
    headless: false,
  });
  page = await browser.newPage();

  for (let i = 0; i < urls.length; i++) {
    const url = urls[i];
    if (!url) continue;
    await save(url);
    console.log("TT > file: a.js:102 > main > i:", i, url);

    // await page.waitForTimeout(30000);
  }
  await page.waitForTimeout(10000);
  await browser.close();
};

const save = async (url) => {
  await page.goto(url, {
    waitUntil: "networkidle0",
  });

  let articles = await page.evaluate(async () => {
    // 将页面滚动到最底部
    await new Promise((resolve, reject) => {
      let totalHeight = 0;
      let distance = 200;
      let timer = setInterval(() => {
        let scrollHeight = document.body.scrollHeight;
        window.scrollBy(0, distance);
        totalHeight += distance;
        if (totalHeight >= scrollHeight) {
          clearInterval(timer);
          resolve();
        }
      }, 100);
    });
  });

  let title = await page.title();
  console.log("TT > file: a.js:134 > save > title:", title);
  title = title.replace(/ /g, "").match(/[\u4e00-\u9fa5]/g).join("");
  await page.pdf({ path: `./pdf/${title}.pdf`, format: "A4" });
};

main();

